import { CHANGE_INPUT, ADD, REMOVE, COMPONENT_CHANGE,LANGUAGE_CHANGE } from "./actionTypes";
import defaultState from "./stateData";
export default (state = defaultState, action) => {
  //就是一个方法函数 处理业务
  if (action.type === CHANGE_INPUT) {
    let newState = JSON.parse(JSON.stringify(state));
    newState.inputValue = action.value;
    return newState;
  }
  if (action.type === ADD) {
    let newData = JSON.parse(JSON.stringify(state));
    newData.list.push(newData.inputValue);
    newData['inputValue']=''
    // console.log("增加",newData);
    return newData;
  }
  if (action.type === REMOVE) {
    let newData = JSON.parse(JSON.stringify(state));
    newData.list.splice(action.index, 1);
    return newData;
  }
  if (action.type === COMPONENT_CHANGE) {
    let newData = JSON.parse(JSON.stringify(state));
    // 如果左侧导航栏没设置组件指向  重指向
    newData.components[0].component =
      action.component == null ? "./index/shopList" : action.component;
    return newData;
  }
  if(action.type===LANGUAGE_CHANGE){
    let newData = Object.assign({},state);
    newData.language = !newData.language;
    return newData;
  }
  return state;
};
